<template>
  <div class="modal">
    <!-- 第一个是遮罩 -->
    <div class="mask" @click="hide"></div>
    <!-- 第二个是具体的内容区域 -->
    <div class="content">
      <!-- title是标题 -->
      <h3>{{ title }}</h3>
      <!-- slot是弹窗内容 -->
      <div class="body">
        <slot name="body"></slot>
      </div>
      <!-- 弹窗按钮 -->
      <div v-if="btntype == 1" class="btn">
        <button @click="submit">确定</button>
        <button @click="cancel">取消</button>
      </div>
      <div v-if="btntype == 2" class="btn">
        <button @click="goMine">前往个人中心</button>
        <button @click="goHome">前往首页</button>
      </div>
    </div>
  </div>
</template>

<script setup>
// 需要接收两个参数， title btntype
// 如何在vue3.0中设置父子组件通讯
import { defineProps, defineEmits } from "vue";
let props = defineProps({
  title: {
    type: String,
    required: true,
  },
  btntype: {
    type: Number,
    required: true,
  },
});
console.log(props);
const emits = defineEmits(["submmit", "cancel", "goHome", "goMine", "hide"]);
const goMine = () => {
  emits("goMine");
};
const goHome = () => {
  emits("goHome");
};
const hide = () => {
  emits("hide");
};
</script>

<style lang="scss" scoped>
.modal {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999; // 确保在最上方
  .mask {
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    position: fixed;
    background-color: rgba(0, 0, 0, 0.2);
  }
  .content {
    width: 3rem;
    height: 2.4rem;
    border-radius: 0.08rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    h3 {
      width: 100%;
      height: 0.7rem;
      line-height: 0.7rem;
      margin-left: 0.2rem;
    }
    .body {
      width: 100%;
      height: 1rem;
      text-align: center;
      line-height: 1rem;
      font-size: 0.16rem;
    }
    .btn {
      width: 100%;
      height: 0.7rem;
      display: flex;
      justify-content: space-around;
      align-items: center;
      button {
        background-color: skyblue;
        border: none;
        width: 1rem;
        height: 0.3rem;
        font-size: 0.14rem;
        border-radius: 0.05rem;
        color: white;
      }
    }
  }
}
</style>
